package com.shrct.businessprocess.product.impl;

import com.shrct.businessprocess.product.RCCompanyService;
import com.shrct.businessprocess.product.RCCompanyServiceEntry;
import com.shrct.businessprocess.product.RCServiceInfo;
import com.shrct.businessprocess.product.impl.RCCompanyServiceImpl;
import com.shrct.businessprocess.product.proxy.RCCompanyServiceEntryProxy;
import edu.fudan.langlab.domain.common.DateRange;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCCOMPANYSERVICEENTRY_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rccompanyserviceentry")
public class RCCompanyServiceEntryImpl extends BaseModelObject implements RCCompanyServiceEntry {
  public RCCompanyServiceEntryImpl() {
    super();
  }
  
  public RCCompanyServiceEntryImpl(final String projectid, final RCCompanyService companyService) {
    super();
    this.projectid = projectid;;
    this.companyService = companyService;
  }
  
  private String projectid;
  
  public String getProjectid() {
    return this.projectid;
  }
  
  public RCCompanyServiceEntry setProjectid(final String projectid) {
    this.projectid = projectid;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "monthes", column = @Column(name = "serviceInfo_monthes") ), @AttributeOverride(name = "workaround", column = @Column(name = "serviceInfo_workaround") ) } )
  @AssociationOverrides(value = { @AssociationOverride(name = "serviceLevel", joinColumns = @JoinColumn(name = "serviceInfo_serviceLevel") ), @AssociationOverride(name = "serviceResponseTime", joinColumns = @JoinColumn(name = "serviceInfo_serviceResponseTime") ), @AssociationOverride(name = "serviceDuration", joinColumns = @JoinColumn(name = "serviceInfo_serviceDuration") ) } )
  private RCServiceInfo serviceInfo = com.shrct.businessprocess.product.RCServiceInfo.create();
  
  public RCServiceInfo getServiceInfo() {
    return this.serviceInfo;
  }
  
  public RCCompanyServiceEntry setServiceInfo(final RCServiceInfo serviceInfo) {
    this.serviceInfo = serviceInfo;
    return this;			
    
  }
  
  private Date start;
  
  public Date getStart() {
    return this.start;
  }
  
  public RCCompanyServiceEntry setStart(final Date start) {
    this.start = start;
    return this;			
    
  }
  
  private Date end;
  
  public Date getEnd() {
    return this.end;
  }
  
  public RCCompanyServiceEntry setEnd(final Date end) {
    this.end = end;
    return this;			
    
  }
  
  @JoinColumn(name = "companyService_id")
  @ManyToOne(targetEntity = RCCompanyServiceImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCCompanyService companyService;
  
  public RCCompanyService getCompanyService() {
    return this.companyService;
  }
  
  public RCCompanyServiceEntry setCompanyService(final RCCompanyService companyService) {
    this.companyService = companyService;
    return this;			
    
  }
  
  public DateRange getRange() {
    DateRange _dateRange = new DateRange();
    final Procedure1<DateRange> _function = new Procedure1<DateRange>() {
        public void apply(final DateRange it) {
          it.setStartDate(RCCompanyServiceEntryImpl.this.start);
          it.setFinishDate(RCCompanyServiceEntryImpl.this.end);
        }
      };
    DateRange _doubleArrow = ObjectExtensions.<DateRange>operator_doubleArrow(_dateRange, _function);
    return _doubleArrow;
  }
  
  public static RCCompanyServiceEntry create(final String projectid, final RCCompanyService companyService, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.product.RCCompanyServiceEntry rCCompanyServiceEntry = new com.shrct.businessprocess.product.impl.RCCompanyServiceEntryImpl(
    	projectid,companyService
    );
    objectFactory.create(rCCompanyServiceEntry);
    return rCCompanyServiceEntry;			
    
  }
  
  public static RCCompanyServiceEntry createRCCompanyServiceEntryImpl(final String projectid, final RCCompanyService companyService, final IObjectFactory objectFactory, final Procedure1<RCCompanyServiceEntry> init) {
    com.shrct.businessprocess.product.RCCompanyServiceEntry rCCompanyServiceEntry = new com.shrct.businessprocess.product.impl.RCCompanyServiceEntryImpl(
    	projectid,companyService
    );
    objectFactory.create(rCCompanyServiceEntry);
    init.apply(rCCompanyServiceEntry);
    
    return rCCompanyServiceEntry;			
    
  }
  
  public RCCompanyServiceEntryProxy toProxy() {
    com.shrct.businessprocess.product.proxy.RCCompanyServiceEntryProxy proxy = new com.shrct.businessprocess.product.proxy.RCCompanyServiceEntryProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
